package zhihui.mobile.manager.shop;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import zhihui.mobile.bean.attention.AttentionInfo;
import zhihui.mobile.bean.shop.SpuInfo;
import zhihui.mobile.config.Config;
import zhihui.mobile.interfaces.net.IHttpCallBackListener;
import zhihui.mobile.manager.IManager;
import zhihui.mobile.manager.user.UserManager;
import zhihui.mobile.net.HttpUtils;

/**
 * Created by 张公铭 on 2017/8/26 0026.
 */

public class ShopAttentionManager implements IManager
{
    private static ShopAttentionManager manager = null;
    private List<SpuInfo> list = new ArrayList<>();

    private synchronized static void createdIns()
    {
        if (manager == null)
        {
            manager = new ShopAttentionManager();
        }
    }

    public static ShopAttentionManager getInstance()
    {
        if (manager == null)
        {
            createdIns();
        }
        return manager;
    }

    public List<SpuInfo> getList()
    {
        return list;
    }

    public void setList(List<SpuInfo> list)
    {
        if (this.list == null)
        {
            this.list = new ArrayList<>();
        }
        this.list.clear();
        this.list.addAll(list);
    }

    /**
     * 初始化我的关注列表
     */
    public void getMyAttention(IHttpCallBackListener listener)
    {
        Map<String, String> params = new HashMap<>();
        params.put("service", "org.zhmm.app.api.cart.Cart");
        params.put("method", "findSkuOnConcernByUserId");

        List<Object> list = new ArrayList<>();
        list.add(UserManager.getInstance().getCurUser().getId());

        HttpUtils.postAes(Config.URL, params, list, listener);
    }

    /**
     * 关注商品
     *
     * @param listener
     * @param list
     */
    public void attention(IHttpCallBackListener listener, List<Object> list)
    {
        Map<String, String> params = new HashMap<>();
        params.put("service", "org.zhmm.app.api.cart.Cart");
        params.put("method", "addConcern");

        HttpUtils.postAes(Config.URL, params, list, listener);
    }

    /**
     * 批量删除
     */
    public void delete(IHttpCallBackListener listener, List<Object> list)
    {
        Map<String, String> params = new HashMap<>();
        params.put("service", "org.zhmm.app.api.cart.Cart");
        params.put("method", "delConcern");

        HttpUtils.postAes(Config.URL, params, list, listener);
    }

    @Override
    public void clear()
    {

    }
}
